




/*
'===============================================================================
'  HNG.Portal.BL.TblDonViTinhManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblDonViTinhManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_LangId="LangId";
				
				public const String Field_TenDonVi="TenDonVi";
				
				public const String Field_Mota="Mota";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblDonViTinhManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(int));
			
						
			
			dt.Columns.Add(Field_TenDonVi,typeof(string));
			
						
			
			dt.Columns.Add(Field_Mota,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblDonViTinhEntity Convert_Entity(TblDonViTinhEntity _TblDonViTinhEntity,TblDonViTinhEntity _TblDonViTinhEntity_XML)
		{	
			
				
			_TblDonViTinhEntity.Id= _TblDonViTinhEntity_XML.Id;
				
			_TblDonViTinhEntity.LangId= _TblDonViTinhEntity_XML.LangId;
				
			_TblDonViTinhEntity.TenDonVi= _TblDonViTinhEntity_XML.TenDonVi;
				
			_TblDonViTinhEntity.Mota= _TblDonViTinhEntity_XML.Mota;
				
			_TblDonViTinhEntity.TrangThai= _TblDonViTinhEntity_XML.TrangThai;
				
			
			return _TblDonViTinhEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblDonViTinhEntity Insert(TblDonViTinhEntity TblDonViTinhEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblDonViTinhEntity, true);
			}
			return TblDonViTinhEntity;
		}

		
		public TblDonViTinhEntity Insert(int Id, int LangId, string TenDonVi, string Mota, bool TrangThai)
		{
			TblDonViTinhEntity _TblDonViTinhEntity = new TblDonViTinhEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblDonViTinhEntity.Id = Id;
				_TblDonViTinhEntity.LangId = LangId;
				_TblDonViTinhEntity.TenDonVi = TenDonVi;
				_TblDonViTinhEntity.Mota = Mota;
				_TblDonViTinhEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblDonViTinhEntity, true);
			}
			return _TblDonViTinhEntity;
		}

		public TblDonViTinhEntity Insert(int LangId, string TenDonVi, string Mota, bool TrangThai)
		{
			TblDonViTinhEntity _TblDonViTinhEntity = new TblDonViTinhEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblDonViTinhEntity.LangId = LangId;
				_TblDonViTinhEntity.TenDonVi = TenDonVi;
				_TblDonViTinhEntity.Mota = Mota;
				_TblDonViTinhEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblDonViTinhEntity, true);
			}
			return _TblDonViTinhEntity;
		}

		public bool Update(TblDonViTinhEntity _TblDonViTinhEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblDonViTinhFields.Id == _TblDonViTinhEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblDonViTinhEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblDonViTinhEntity _TblDonViTinhEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblDonViTinhEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int LangId, string TenDonVi, string Mota, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDonViTinhEntity _TblDonViTinhEntity = new TblDonViTinhEntity(Id);
				if (adapter.FetchEntity(_TblDonViTinhEntity))
				{
				
					_TblDonViTinhEntity.LangId = LangId;
					_TblDonViTinhEntity.TenDonVi = TenDonVi;
					_TblDonViTinhEntity.Mota = Mota;
					_TblDonViTinhEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblDonViTinhEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDonViTinhEntity _TblDonViTinhEntity = new TblDonViTinhEntity(Id);
				if (adapter.FetchEntity(_TblDonViTinhEntity))
				{
					adapter.DeleteEntity(_TblDonViTinhEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblDonViTinhEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDonViTinhEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(int LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDonViTinhEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenDonVi(string TenDonVi)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.TenDonVi == TenDonVi);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDonViTinhEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByMota(string Mota)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDonViTinhEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblDonViTinhEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblDonViTinhEntity SelectOne(int Id)
		{
			TblDonViTinhEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblDonViTinhEntity _TblDonViTinhEntity = new TblDonViTinhEntity(Id);
				if (adapter.FetchEntity(_TblDonViTinhEntity))
				{
					toReturn = _TblDonViTinhEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblDonViTinhCollection = new EntityCollection( new TblDonViTinhEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDonViTinhCollection, null, 0, null);
			}
			return _TblDonViTinhCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDonViTinhCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDonViTinhCollection, filter, 0, null);
			}
			return _TblDonViTinhCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDonViTinhCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(int LangId)
		{
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDonViTinhCollection, filter, 0, null);
			}
			return _TblDonViTinhCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(int LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDonViTinhCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenDonVi(string TenDonVi)
		{
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.TenDonVi == TenDonVi);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDonViTinhCollection, filter, 0, null);
			}
			return _TblDonViTinhCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenDonViRDT(string TenDonVi)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.TenDonVi == TenDonVi);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDonViTinhCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByMota(string Mota)
		{
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDonViTinhCollection, filter, 0, null);
			}
			return _TblDonViTinhCollection;
		}
		
		// Return DataTable
		public DataTable SelectByMotaRDT(string Mota)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDonViTinhCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblDonViTinhCollection, filter, 0, null);
			}
			return _TblDonViTinhCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblDonViTinhCollection = new EntityCollection(new TblDonViTinhEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblDonViTinhFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblDonViTinhCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
